#ifndef __MPU6050_H__
#define __MPU6050_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define MPU6050_DATARATE_8KHZ  0  /*!< Sample rate set to 8 kHz */
#define MPU6050_DATARATE_4KHZ  1  /*!< Sample rate set to 4 kHz */
#define MPU6050_DATARATE_2KHZ  3  /*!< Sample rate set to 2 kHz */
#define MPU6050_DATARATE_1KHZ  7  /*!< Sample rate set to 1 kHz , the acc higthest*/
#define MPU6050_DATARATE_500HZ 15 /*!< Sample rate set to 500 Hz */
#define MPU6050_DATARATE_250HZ 31 /*!< Sample rate set to 250 Hz */
#define MPU6050_DATARATE_125HZ 63 /*!< Sample rate set to 125 Hz */
#define MPU6050_DATARATE_100HZ 79 /*!< Sample rate set to 100 Hz */

// Parameters for accelerometer range
#define MPU6050_ACCELEROMETER_RANGE_2G  0x00 /*!< Range is +- 2G */
#define MPU6050_ACCELEROMETER_RANGE_4G  0x01 /*!< Range is +- 4G */
#define MPU6050_ACCELEROMETER_RANGE_8G  0x02 /*!< Range is +- 8G */
#define MPU6050_ACCELEROMETER_RANGE_16G 0x03 /*!< Range is +- 16G */

#define MPU6050_GYROSCOPE_RANGE_250S  0x00 /*!< Range is +- 250 degrees/s */
#define MPU6050_GYROSCOPE_RANGE_500S  0x01 /*!< Range is +- 500 degrees/s */
#define MPU6050_GYROSCOPE_RANGE_1000S 0x02 /*!< Range is +- 1000 degrees/s */
#define MPU6050_GYROSCOPE_RANGE_2000S 0x03 /*!< Range is +- 2000 degrees/s */

#define MPU6050_FILTER_260HZ_0MS    0x00
#define MPU6050_FILTER_184HZ_2MS    0x01
#define MPU6050_FILTER_94HZ_3MS     0x02
#define MPU6050_FILTER_44HZ_5MS     0x03
#define MPU6050_FILTER_21HZ_8MS     0x04
#define MPU6050_FILTER_10HZ_13MS    0x05
#define MPU6050_FILTER_5HZ_19MS     0x06

typedef struct {
  void *bus;
  float coefficient_acc;
  float coefficient_gyros;
} mpu6050_t;

typedef struct {
  uint8_t  acc_range;
  uint8_t  gyro_range;
  uint8_t  data_rate;
  uint8_t  filter;
  uint8_t  fifo_en;
} mpu6050_cfg_t;

typedef struct {
  int16_t acc_x;
  int16_t acc_y;
  int16_t acc_z;
  float coefficient_acc;

  int16_t gyros_x;
  int16_t gyros_y;
  int16_t gyros_z;
  float coefficient_gyros;

  int16_t temperature;


} mpu6050_raw_t;

#define MPU6050_I2C_ADDR (0x68<<1)

int mpu6050_init(mpu6050_t *pdev);
int mpu6050_set_cfg(mpu6050_t *pdev, mpu6050_cfg_t *pcfg);
int mpu6050_get_cfg(mpu6050_t *pdev, mpu6050_cfg_t *pcfg);
int mpu6050_get_raw(mpu6050_t *pdev, mpu6050_raw_t *praw);

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __MPU6050_H__ */